import time
import random
import hashlib
# Request Types Define
WCREQ_PLAYER_INFORMATION_GET = "87b574c6c34f0318a8533ff9dce7890a"
WCREQ_WORLD_GET = "5c416921ca644f1f1bcb304f2591b155"

# Dicts
ModuleRequests = {}
MainAnswers = {}
WaitingFunctions = {}


def getMD5(text: str) -> str:
    md = hashlib.md5()
    md.update(text.encode(encoding="UTF-8"))
    return md.hexdigest()


def request(retype: str, indata: dict = {}) -> str:
    reID: str = retype+str(time.time())+str(random.random())
    reID = getMD5(reID)
    ModuleRequests[reID] = {"retype": retype, "indata": indata}
    return reID


def get_answer(reID: str) -> dict:
    return MainAnswers[reID]


def get_requests() -> dict:
    return ModuleRequests


def answer(reID: str, outdata: dict) -> None:
    MainAnswers[reID] = outdata


def waituntil(reID: str, after) -> None:
    WaitingFunctions[reID] = after


def get_waiting_functions() -> dict:
    return WaitingFunctions


def reset() -> None:
    global ModuleRequests, WaitingFunctions
    ModuleRequests = {}
    WaitingFunctions = {}
